<template>
	<view>
		<!-- 订单状态栏Tab-结束 -->
		<fu-loading v-if="isShowLoading"></fu-loading>
		<block v-else>
		  <!-- 订单列表-开始 -->
		  <view class="list">
		    <block v-for="(item, index) in lists" :key="index">
		      <view v-if="tabCurrentIndex != 5" class="order-item">
		        <!-- 订单头部-订单编号&订单状态-开始 -->
		        <view class="i-top b-b">
		          <view class="time">
		            <text v-if="item.send_type != 1">{{ i18n['订单编号'] }}: {{ item.order_sn }}</text>
		            <view v-else class="flex align-center">
		              <!-- <image class="head" style="width:40rpx;height:30rpx" src="../../static/address_3.png" mode=""></image> -->
		              <text>{{i18n['自取订单']}}</text>
		            </view>
		          </view>
		          <view class="so">
		            <text v-if="item.send_type != 1" class="text-theme">{{ item.status | filterStatus }}</text>
		            <text v-else class="text-theme">{{ item.status | filterInviteStatus }}</text>
		          </view>
		        </view>
		        <!-- 订单头部-订单编号&订单状态-结束 -->
		        <!-- 订单商品列表-结束 -->
		        <view class="goods-box" @click.stop="navToOrderDetail(item, index)">
		          <view class="goods-box-single" v-for="(goodsItem, goodsIndex) in item.goods" :key="goodsIndex">
		            <view class="goods-img radius overHidden">
		              <fu-image :src="goodsItem.goods_thumb" mode="aspectFill"></fu-image>
		            </view>
		            <view class="right">
		              <view>
		                <view class="text-df text-333 text-cut-2">{{ goodsItem.goods_name }}</view>
		                <view class="text-sm text-999 text-cut" style="margin-top:8rpx;">{{ goodsItem.sku_name }}</view>
		              </view>
		              <!-- 状态 -->
		              <!-- 判断是否成团  拼图订单 已支付 未成团-->
		              <view
		                v-if="item.order_type == 5 && item.status == 1 && item.group_info && item.group_info.is_full != 1"
		                class="text-right" style="color: rgb(247, 173, 50); font-size: 24rpx">
		                {{ i18n['未成团'] }}
		              </view>
		              <!-- 判断是否成团  预售订单 已支付 未付尾款（尾款是否完成）-->
		              <view v-if="item.order_type == 7 && item.status == 1 && item.final_status != 1" class="text-right text-orange text-sm">
		                {{ i18n['尾款未支付'] }}
		              </view>
		              <view class="text-right text-orange text-sm" v-if="goodsItem.order_refund_status == -2">{{ i18n['售后取消'] }}</view>
		              <view class="text-right text-orange text-sm" v-if="goodsItem.order_refund_status == -1">{{ i18n['申请驳回'] }}</view>
		              <view class="text-right text-orange text-sm" v-if="goodsItem.order_refund_status == 0">{{ i18n['售后中'] }}</view>
		              <view class="text-right text-orange text-sm" v-if="goodsItem.order_refund_status == 3">{{ i18n['退款成功'] }}</view>
		              <view class="text-right text-orange text-sm" v-if="goodsItem.order_refund_status == 2">{{ i18n['商家确认收货'] }}</view>
		              <view class="text-right text-orange text-sm" v-if="goodsItem.order_refund_status == 1">{{ i18n['同意申请'] }}</view>
		              <view class="text-right text-orange text-sm" v-if="goodsItem.order_refund_status == -999">{{ i18n['申请售后'] }}</view>
		              <view class="flex justify-between align-center">
		                <text class="text-theme text-bold">
		                  <text class="text-price text-xs"></text>
		                  <text class="text-lg">{{ goodsItem.shop_price | filterPriceInt}}.</text>
		                  <text class="text-xs">{{ goodsItem.shop_price | filterPriceFloat}}</text>
		                </text>
		                <text class="text-sm text-999">x {{ goodsItem.num }}</text>
		              </view>
		            </view>
		          </view>
		        </view>
		        <!-- 订单列表-结束 -->
		        <!-- 订单操作模块 -->
		        <view>
		          <!-- 预售订单区分 -->
		          <view v-if="item.order_type == 7" class="price-box">
		            <view class="oredr-type cu-tag round line-red" v-if="!isShowLoading">{{ i18n['预售'] }}</view>
		            <view>
		              <text>
		                <text>{{ i18n['定金'] }}：</text>
		                <text class="text-bold">
		                  <text class="text-price text-xs"></text>
		                  <text class="text-lg">{{ item.payable_money | filterPriceInt}}.</text>
		                  <text class="text-xs">{{ item.payable_money | filterPriceFloat}}</text>
		                </text>
		              </text>
		              <text>
		                <text>{{ i18n['尾款'] }}：</text>
		                <text class="text-bold">
		                  <text class="text-price text-xs"></text>
		                  <text class="text-lg">{{ item.final_order.payable_money | filterPriceInt}}.</text>
		                  <text class="text-xs">{{ item.final_order.payable_money | filterPriceFloat }}</text>
		                </text>
		              </text>
		            </view>
		          </view>
		          <!-- 拼团订单 -->
		          <view v-else-if="item.order_type == 5" class="price-box">
		            <view class="oredr-type cu-tag round line-red" v-if="!isShowLoading">{{ i18n['拼团'] }}</view>
		            <view>
		              <text class="text-sm text-999">{{i18n['共']}}</text>
		              <text class="text-sm text-999">1</text>
		              <text class="text-sm text-999">{{i18n['件商品']}}</text>
		              <text class="text-sm margin-lr-xs text-999">{{i18n['实付款']}}</text>
		              <text class="text-bold">
		                <text class="text-price text-xs"></text>
		                <text class="text-lg">{{ item.payable_money |filterPriceInt}}.</text>
		                <text class="text-xs">{{ item.payable_money | filterPriceFloat}}</text>
		              </text>
		            </view>
		          </view>
		          <!-- 秒杀订单 -->
		          <view v-else-if="item.activity_type == 1" class="price-box">
		            <view class="oredr-type cu-tag round line-red" v-if="!isShowLoading">{{ i18n['秒杀'] }}</view>
		            <view>
		              <text class="text-sm text-999">{{i18n['共']}}</text>
		              <text class="text-sm text-999">1</text>
		              <text class="text-sm text-999">{{i18n['件商品']}}</text>
		              <text class="text-sm margin-lr-xs text-999">{{i18n['实付款']}}</text>
		              <text class="text-bold">
		                <text class="text-price text-xs"></text>
		                <text class="text-lg">{{ item.payable_money | filterPriceInt}}.</text>
		                <text class="text-xs">{{ item.payable_money | filterPriceFloat}}</text>
		              </text>
		            </view>
		          </view>
		          <!-- 普通商品 -->
		          <view class="price-box" style="justify-content: flex-end;" v-else>
		            <view>
		              <text class="text-sm text-999">{{i18n['共']}}</text>
		              <text class="text-sm text-999">1</text>
		              <text class="text-sm text-999">{{i18n['件商品']}}</text>
		              <text v-if="item.status == 0  || item.status == -1"
		                class="text-sm margin-lr-xs text-999">{{i18n['应付款']}}</text>
		              <text v-else class="text-sm margin-lr-xs text-999">{{i18n['实付款']}}</text>
		              <text class="text-bold">
		                <text class="text-price text-xs"></text>
		                <text class="text-lg">{{ item.payable_money | filterPriceInt }}.</text>
		                <text class="text-xs">{{ item.payable_money | filterPriceFloat }}</text>
		              </text>
		            </view>
		          </view>
		        </view>
		        <view class="action-box">
		          <!-- <button class="action cu-btn round" @click.stop="navToOrderDetail(item, index)">{{ i18n['查看详情'] }}</button> -->
		          <button class="action cu-btn" v-if="isContentShow([-1, 4, 7], item.status)"
		            @click.stop="delOrder(item, index)">{{ i18n['删除订单'] }}</button>
		          <button class="action cu-btn recom" v-if="item.status == 0" @tap.stop="showCancelReason(item, index)">{{
		            i18n['取消订单'] }}</button>
		          <!-- invoice_status 0展示申请开票 1已申请开票 2已开过票 -->
		          <!-- item.status 0未付款 -1 已取消 item.payable_money == 0不支持开发票   -->
		          <button class="action cu-btn recom"
		            v-if="item.order_refund_status == 0 && item.status != 0 && item.status != -1 && item.payable_money > 0"
		            @tap.stop="handleInvoice(item.invoice_status, item.order_sn, item.payable_money)">
		            <text v-if="item.invoice_status == 0">{{ i18n['申请开票'] }}</text>
		            <!-- <text v-if="item.invoice_status==1">修改发票</text> -->
		            <text v-if="item.invoice_status == 1 || item.invoice_status == 2">{{ i18n['查看发票'] }}</text>
		          </button>
		          <button class="action cu-btn round" v-if="isContentShow([2,3], item.status)"
		            @click.stop="seelogs(item.order_sn)">{{ i18n['查看物流'] }}</button>
		          <!-- 申请售后 假 -->
		          <button class="action cu-btn round recom"
		            v-if="item.order_refund_status == 0 && item.status >= 1 && item.order_type != 7 && item.order_type != 5"
		            @click.stop="navToOrderDetail(item, index)"
		            >
		            {{ i18n['申请售后'] }}
		          </button>
		          <!-- 预售订单 单独按钮 -->
		          <button class="action cu-btn round bgclor"
		            v-if="item.order_type == 7 && item.final_status != 1 && item.status == 1"
		            @click.stop="toPay(item.final_order.order_sn, item.order_type)"
		            :disabled="item.activity_time && item.activity_time.is_pay == 0">
		            {{ i18n['支付尾款'] }}
		          </button>
		          <button class="action active cu-btn" v-if="item.status == 0"
		            @click.stop="toPay(item.order_sn, item.order_type)">{{ i18n['去支付'] }}</button>
		
		          <button class="action cu-btn" v-if="item.status == 3   && !item.is_refund"
		            @click.stop="evaluateOrder(item.order_sn, item.order_type, item.goods)">{{ i18n['评价'] }}</button>
		          <!-- 是否需要提醒收货 start -->
		          <!-- 预售订单   -->
		          <button
		            v-if="item.order_type == 7 && item.final_status == 1 && item.is_remind.info == 0 && item.status == 1"
		            class="action cu-btn round bgclor" @click.stop="remindOrder(item.order_sn)">
		            {{ i18n['提醒发货'] }}
		          </button>
		          <button
		            v-if="item.order_type == 7 && item.final_status == 1 && item.is_remind.info == 1 && item.status == 1"
		            class="cu-btn round action have_click" disabled="false">
		            {{ i18n['已提醒'] }}
		          </button>
		          <!-- 拼团订单  -->
		          <button
		            v-if="item.order_type == 5 && item.is_remind.info == 0 && item.status == 1 && item.group_info && item.group_info.is_full == 1"
		            class="action cu-btn round bgclor" @click.stop="remindOrder(item.order_sn)">
		            {{ i18n['提醒发货'] }}
		          </button>
		          <button
		            v-if="item.order_type == 5 && item.group_info && item.is_remind.info == 1 && item.status == 1 && item.group_info && item.group_info.is_full == 1"
		            class="cu-btn round action have_click" disabled="false">
		            {{ i18n['已提醒'] }}
		          </button>
		          <!-- 普通商品按钮判断 排除预售7和拼团5 -->
		          <button
		            v-if="item.is_remind.info == 0 && item.status == 1 && item.order_type != 5 && item.order_type != 7"
		            class="action cu-btn round bgclor" @click.stop="remindOrder(item.order_sn)">
		            {{ i18n['提醒发货'] }}
		          </button>
		          <button
		            v-if="item.is_remind.info == 1 && item.status == 1 && item.order_type != 5 && item.order_type != 7"
		            class="cu-btn round action have_click" disabled="false">
		            {{ i18n['已提醒'] }}
		          </button>
		          <!-- 提醒收货 end -->
		          <button class="action active cu-btn round" v-if="item.status == 2"
		            @click.stop="receiveOrder(item, index)">{{ i18n['确认收货'] }}</button>
		        </view>
		        <!-- 订单操作模块-结束 -->
		      </view>
		      <view v-else class="order-item" @click="toDetail(item)">
		        <view class="i-top b-b">
		          <view class="time">
		            <text>{{ i18n['订单编号'] }}: {{ item.server_no }}</text>
		          </view>
		          <view class="so flex align-center">
		            <text class="refund-tag">{{ item.refund_type | filterRefundType }}</text>
		            <text class="text-theme">{{ item.status | filterRefundStatus(item.refund_type,item.express_no) }}</text>
		          </view>
		        </view>
		        <view class="flex margin-top-sm padding-bottom solid-bottom">
		          <view class="block-200 margin-right-sm radius overHidden">
		            <fu-image :src="item.goods_thumb" mode="aspectFill"></fu-image>
		          </view>
		          <view class="flex-sub flex flex-direction justify-between overHidden">
		            <view>
		              <view class="text-df text-cut-2">{{ item.goods_name }}</view>
		              <view class="text-sm text-999 text-cut margin-top-xs">{{ item.sku_name || '' }}</view>
		            </view>
		            <view class="flex justify-between align-center">
		              <view class="text-theme">
		                <text class="text-price text-sm"></text>
		                <text class="text-lg">{{ item.goods_money }}</text>
		              </view>
		              <view class="text-sm text-999">x{{ item.goods_num || '1' }}</view>
		            </view>
		          </view>
		        </view>
		        <view class="padding-top-sm padding-bottom flex justify-end">
		          <view class="action-btn round margin-left-sm" @click.stop="toDetail(item)">查看详情</view>
		          <view class="action-btn round margin-left-sm" v-if="item.status == '0'" @click.stop="cancelAfter(item)">
		            取消申请</view>
		          <view class="action-btn round margin-left-sm" v-if="item.status == '1' && item.refund_type == '2' && !item.express_no"
		            @click.stop="sendLog(item.id)">寄回商品</view>
		        </view>
		      </view>
		    </block>
		  </view>
		  <!-- 订单列表-结束 -->
		  <!-- 空布局 -->
		  <fu-empty-ui v-if="lists.length == 0 && isInit"></fu-empty-ui>
		  <!-- 加载状态 -->
		  <uni-load-more v-if="lists.length >= 5" :status="status"></uni-load-more>
		</block>
		<!-- 取消订单弹出层-开始 -->
		<fu-popup v-model="showPopup" mode="bottom" border-radius="24">
		  <view class="cancel-order-pop">
		    <view class="flex justify-between align-center" style="padding:0 32rpx;">
		      <view class="text-999 text-weight-400 text-df" @click="showPopup = false">{{ i18n['取消'] }}</view>
		      <view class="pop-title">{{ i18n['取消订单'] }}</view>
		      <view class="text-red text-weight-400 text-df" @click="cancelOrder()">{{ i18n['确定'] }}</view>
		    </view>
		    <view class="pop-count">
		      <view class="tips text-sm">{{ i18n['请选择取消订单原因'] }}</view>
		      <scroll-view scroll-y="true" style="max-height: 400rpx; min-height: 200rpx">
		        <view class="pop-count-list">
		          <view @click="onChangeReson(item, index)" class="item flex align-center justify-between"
		            v-for="(item, index) in reasonList" :key="index">
		            <view class="item-label">{{ item.reason }}</view>
		           <!-- <image v-if="index == cancelObj.current" class="item-img" src="../../static/icon-select-2.png"
		              mode="aspectFit"></image> -->
		            <!-- <image v-else src="../../static/icon-select-1.png" mode="aspectFit" class="item-img"></image> -->
		          </view>
		        </view>
		      </scroll-view>
		    </view>
		  </view>
		</fu-popup>
		<!-- 取消订单弹出层-结束 -->
		<!-- 断网监测 -->
		<fu-notwork></fu-notwork>
	</view>
</template>

<script>
  /** 订单状态列表
   * all 全部订单
   * unpay 待付款订单
   * unship 待发货订单
   * unreceive 待收货订单
   * finish 待评价订单
   * refund 退款/售后
   * */

  export default {
    data() {
      return {
        isShowLoading: false, // 是否显示加载组件  加载中状态
        tabCurrentIndex: 0, // tab切换选中状态下标
        navList: [
          {
            state: 0,
            text: global.i18n['全部'],
            type: 'all'
          },
          {
            state: 1,
            text: global.i18n['待付款'],
            type: 'unpay'
          },
          {
            state: 2,
            text: global.i18n['待发货'],
            type: 'unship'
          },
          {
            state: 3,
            text: global.i18n['待收货'],
            type: 'unreceive'
          },
          {
            state: 4,
            text: global.i18n['待评价'],
            type: 'finish'
          },
          {
            state: 5,
            text: global.i18n['退款/售后'],
            type: 'refund'
          }
        ], // 订单状态切换列表
        lists: [], // 订单列表
        page: 1, // 订单列表页码  表示正在请求哪一页
        size: 10, // 订单列表每页多少条数据
        status: 'more', // 表示是否有数据可以请求
        isInit: false, // 初始化订单
        typeSeatrch: null, // 搜索栏的状态   页面暂无搜索功能
        searchOrderKey: '', // 搜索栏文字
        isSearchState: false, // 搜索栏的状态
        showPopup: false, // 控制取消订单弹出层是否显示
        reasonList: [], //取消原因列表
        cancelObj: {
          //订单取消对象
          current: -1, //当前原因索引
          id: '', //档原因id
          orderSn: null, //要取消的订单号
          index: null, //要取消的订单在列表中的索引
          orderItem: {} //当前订单对象
        }
      };
    },
    onLoad(options) {
      // this.setNavigationBarTitle(this.i18n['我的订单']);
      // 跳转订单列表未携带参数时默认全部状态
      const { type = 'all' } = options;
      // 获取当前选中状态的tab数据 包括下标，类型等
      const _item = this.navList.find(item => item.type == type);

      this.tabCurrentIndex = _item.state;
      this.type = _item.type;
      this.typeSeatrch = _item.type;

      // this.getOrderList(true);
      this.getReasonList();
      this.refreshOrderList(true);
      // 监听页面更新
      uni.$on('onPageUpdata', this.onPageUpdata);
    },
    onShow() {
    },
    onUnload() {
      // 移除页面更新监听
      uni.$off('onPageUpdata', this.onPageUpdata);
    },
    methods: {
      // 发票
      handleInvoice(status, order_sn, payable_money) {
        let url = `/pages/invoice/invoice/apply-invoice/index?order_sn=${order_sn}&payable_money=${payable_money}&status=${status}`;
        // status == 0去申请开票
        if (status == 0) {
          uni.navigateTo({
            url: url
          });
        }
        // status == 1已申请过发票  可以修改发票（修改，撤销发票）   只有查看了发票才知道是否需要修改
        //  status == 2发票已经开票成功  不能再修改
        if (status == 1 || status == 2) {
          uni.navigateTo({
            url: '/pages/invoice/invoice/invoice-info/index?order_sn=' + order_sn + '&payable_money=' + payable_money
          });
        }
      },
      // 查看物流
      seelogs(orderSn) {
        console.log('查看物流');
        this.$urouter.navigateTo({
          url: '/pages/order/orderdetail/express-delivery/index',
          params: {
            order_sn: orderSn
          }
        });
      },
      // 提醒发货
      remindOrder(sn) {
        this.$api
          .post(global.apiUrls.postRemindShipment, {
            order_sn: sn
          })
          .then(res => {
            // console.log("res: " + JSON.stringify(res));
            this.$message.info(this.i18n['已提醒,请耐心等待']);
            this.refreshOrderList();
          })
          .catch(err => {
            console.log('err: ' + JSON.stringify(err));
          });
      },
      /**
       * @description 监听页面更新的回调函数
       * @param {Object} res = 要更新的配置参数
       */
      onPageUpdata(res) {
        let index = res.data.itemIndex;
        let item = this.lists[index];
        switch (res.type) {
          case 1: // 取消订单
            if (this.tabCurrentIndex == 0) {
              item.status = -1;
              this.lists.splice(index, 1, item);
            } else {
              this.lists.splice(index, 1);
            }
            break;
          case 2: //删除订单
            this.lists.splice(index, 1);
            break;
          case 3: //确认订单
            console.log('确认订单', index);
            if (this.tabCurrentIndex == 0) {
              item.status = 3;
              this.lists.splice(index, 1, item);
            } else {
              this.lists.splice(index, 1);
            }
            break;
          case 4: // 提醒收货
            this.refreshOrderList();
            break;
          case 5: // 发票 //评价
            this.refreshOrderList();
            break;
            case 6: // 删除
            this.refreshOrderList();
            break;
          default:
            break;
        }
      },
      // ok
      tabClick(e) {
        let index = e.index;
        this.tabCurrentIndex = index;
        this.type = this.navList[index].type;
        this.typeSeatrch = this.navList[index].type;
        this.refreshOrderList(true);
      },

      /**
       * @description 获取列表
       * @param {Boolean} value = 是否需要展示加载动画
       */
      getOrderList(value) {
        if (this.status != 'more') return;
        this.status = 'loading';
        let data = {
          type: this.type,
          page: this.page,
          list_rows: this.size,
					// order_type:3,//3:普通商品4：积分商品5:拼团订单6:秒杀订单7:预售订单9:折扣订单11:会员限购订单12:积分商
          search_name: this.searchOrderKey
        };
        // console.log('请求的数据', data);
        if (this.page == 1 && value) {
          this.isShowLoading = true;
        }
        if (this.tabCurrentIndex != 5) {
          this.$api
            .post(global.apiUrls.getAdvanceOrderList, data)
            .then(res => {
              console.log('订单列表', res);
              this.isShowLoading = false;
              if (res.data.code == 1) {
                var curPageData = res.data.data.list;
                if (this.page == 1) this.lists = [];
                this.lists = this.lists.concat(curPageData);
                console.log('上拉加载', curPageData.length, this.size);
                if (curPageData.length >= this.size) {
                  this.status = 'more';
                  this.page++;
                } else {
                  this.status = 'noMore';
                }
              } else {
                this.$message.info(res.data.msg);
              }
                 //是否显示去评价 
                 if (this.lists.length > 0) {
                this.lists.forEach((item) => {
                  if (item.status == 3) {
                    item.goods.forEach((goodItem) => {
                      console.log(goodItem)
                      item.is_refund = false
											if (goodItem.order_refund_status || goodItem.order_refund_status == 0) {
												item.is_refund = true
											}
                    })
                  }
                })
              }
              this.isInit = true;
              uni.stopPullDownRefresh();
            })
            .catch(err => {
              this.isShowLoading = false;
              uni.stopPullDownRefresh();
            });
        } else {
          this.$api
            .get(global.apiUrls.getGoodsAfterSale, {
              page: this.page,
              list_rows: this.size
            })
            .then(res => {
              console.log('售后单列表', res);
              this.isShowLoading = false;
              if (res.data.code == 1) {
                var curPageData = res.data.data.data;
                if (this.page == 1) this.lists = [];
                this.lists = this.lists.concat(curPageData);
                if (curPageData.length >= this.size) {
                  this.status = 'more';
                  this.page++;
                } else {
                  this.status = 'noMore';
                }
              } else {
                this.$message.info(res.data.msg);
              }

              console.log(this.lists)
           
              this.isInit = true;
              uni.stopPullDownRefresh();
            })
            .catch(err => {
              this.isShowLoading = false;
              uni.stopPullDownRefresh();
            });
        }
      },

      /**
       * @description 获取取消原因列表
       */
      getReasonList() {
        this.$api
          .post(global.apiUrls.getReasonList, {
            type: 2
          })
          .then(res => {
            let data = res.data;
            console.log('获取取消原因列表', data.data);
            if (data.code == 1) {
              this.reasonList = data.data;
            }
          });
      },

      /**
       * @description 展示取消原因
       * @param {Object} item = 当前订单项对象
       * @param {Number} index = 当前订单在列表中的索引
       */
      showCancelReason(item, index) {
        this.cancelObj.orderSn = item.order_sn;
        this.cancelObj.index = index;
        this.cancelObj.orderItem = item;
        this.cancelObj.current = -1;
        this.cancelObj.id = '';
        this.showPopup = true;
      },

      /**
       * @description 取消订单
       * @param {string} sn = 订单号
       * */
      cancelOrder() {
        if (!this.cancelObj.id) return this.$message.info(this.i18n['请选择取消原因']);
        uni.showLoading({
          title: this.i18n['操作中'],
          mask: true
        });
        this.$api
          .post(global.apiUrls.postCancelOrder, {
            order_sn: this.cancelObj.orderSn,
            return_id: this.cancelObj.id
          })
          .then(res => {
            let data = res.data;
            uni.hideLoading();
            this.$message.info(data.msg);
            if (data.code == 1) {
              this.showPopup = false;
              this.cancelObj.id = '';
              if (this.tabCurrentIndex == 0) {
                this.cancelObj.orderItem.status = -1;
                this.lists.splice(this.cancelObj.index, 1, this.cancelObj.orderItem);
              } else {
                this.lists.splice(this.cancelObj.index, 1);
              }
            }
          })
          .catch(err => {
            uni.hideLoading();
            console.log('err: ' + JSON.stringify(err));
          });
      },

      /**
       * @description 监听切换取消原因
       * @param {Object} item = 当前原因项
       * @param {Number} index = 当前原因在列表中的索引
       */
      onChangeReson(item, index) {
        if (this.cancelObj.current == index) return false;
        this.cancelObj.current = index;
        this.cancelObj.id = item.id;
      },

      /**
       * @description 删除订单
       * @param {Object} item = 当前订单项对象
       * @param {Number} index = 当前订单在列表中的索引
       */
      delOrder(item, index) {
        this.$util.showModal({
          title: this.i18n['确认删除此订单?'],
          content: this.i18n['删除后不可恢复'],
          success: res => {
            if (res.confirm) {
              this.$api
                .post(global.apiUrls.postDelOrder, {
                  order_sn: item.order_sn
                })
                .then(res => {
                  let data = res.data;
                  if (data.code == 1) {
                    this.$message.info(this.i18n['删除成功']);
                    this.lists.splice(index, 1);
                  } else {
                    this.$message.info(data.msg);
                  }
                })
                .catch(err => {
                  console.log('err: ' + JSON.stringify(err));
                });
            }
          }
        });
      },

      /**
       * @description 去支付
       * @param {string} sn = 订单号
       * @param {Number} type = 订单类型
       * */
      toPay(sn, type) {
        this.$urouter.navigateTo({
          url: '/pages/order/order-process/pay-order/index',
          params: {
            order_sn: sn,
            order_type: type
          }
        });
      },

      /**
       * @description 确认收货
       * @param {Object} item = 当前订单项对象
       * @param {Number} index = 当前订单在列表中的索引
       * */
      receiveOrder(item, index) {
        this.$util.showModal({
          title: this.i18n['提示'],
          content: this.i18n['您是否确认收到货物?'],
          success: res => {
            if (res.confirm) {
              this.$api
                .post(global.apiUrls.postConfirmOrder, {
                  order_sn: item.order_sn
                })
                .then(res => {
                  res = res.data;
                  if (res.code == 1) {
                    if (this.tabCurrentIndex == 0) {
                      item.status = 3;
                      this.lists.splice(index, 1, item);
                    } else {
                      this.lists.splice(index, 1);
                    }
                  } else {
                    this.$message.info(res.msg);
                  }
                })
                .catch(err => {
                  console.log('err: ' + JSON.stringify(err));
                });
            }
          }
        });
      },

      /**
       * @description 查看订单详情
       * @param {String} item = 订单列表项
       * @param {Number} index = 当前订单在列表中的索引
       * */
      navToOrderDetail(item, index) {
        this.$urouter.navigateTo({
          url: '/pages/order/orderdetail/order-detail/index',
          params: {
            order_sn: item.order_sn,
            status: item.status,
            order_type: item.order_type,
            itemIndex: index
          }
        });
      },

      /**
       * @description 去评价
       * @param {string} order_sn 订单号  order_type  订单类型 item = 订单列表项
       * */
      evaluateOrder(order_sn, order_type, item) {
        console.log('存放的', item);
        uni.setStorageSync('order_goods_list', JSON.stringify(item));
        this.$urouter.navigateTo({
          url: '/pages/order/evaluation/order-evaluation/index',
          params: {
            order_sn: order_sn,
            order_type: order_type
          }
        });
      },

      /**
       * @description 重置列表
       * @param {string} value
       * */
      refreshOrderList(value) {
        this.page = 1;
        this.status = 'more';
        if (value) {
          this.getOrderList(true);
        } else {
          this.getOrderList();
        }
      },

      /**
       * @description 返回上一页
       * @param {string} value
       * */
      back() {
        uni.navigateBack({
          delta: 2
        });
      },

      /**
       * @description 判断内容是否显示
       * @param {String} arr = 要判端数组
       * @param {String | Number} val = 要判的值
       */
      isContentShow(arr, val) {
        return arr.includes(val * 1);
      },
      // 提交物流信息
      sendLog(id) {
        this.$urouter.navigateTo({
          url: '/pages/order/afterorder/afterorder-sendback/index',
          params: {
            id: id
          }
        });
      },
      // 取消申请
      cancelAfter(item) {
        let that = this;
        if (that.is_click) return;
        this.$util.showModal({
          title: this.i18n['提示'],
          content: this.i18n['确定取消申请吗？'],
          cancelText: this.i18n['取消'],
          confirmText: this.i18n['确定'],
          success: res => {
            if (res.confirm) {
              that.$api
                .post(global.apiUrls.getGoodsAfterSaleCentel, {
                  id: item.id
                })
                .then(res => {
                  console.log(res);
                  that.$message.info(res.data.msg);
                  if (res.data.code == 1) {
                    this.$message.info("取消成功");
                    this.refreshOrderList(true);
                  }
                })
                .catch(err => {
                  console.log('err: ' + JSON.stringify(err));
                });
            }
          }
        });
      },
      // 去售后详情
      toDetail(item) {
        this.$urouter.navigateTo({
          url: '/pages/order/afterorder/afterorder-detail/index',
          params: {
            id: item.id
          }
        })
      },
    },
    onPullDownRefresh() {
      // 下拉刷新， 初始化订单列表数据
      this.refreshOrderList(true);
    },
    onReachBottom() {
      // 上拉加载更多数据
      this.getOrderList();
    },
    filters: {
      // 订单状态过滤器  status每个值代表的状态
      filterStatus(val) {
        switch (val) {
          case 0:
            return global.i18n['待付款'];
          case 1:
            return global.i18n['待发货'];
          case 2:
            return global.i18n['待收货'];
          case 3:
            return global.i18n['待评价'];
          case 4:
            return global.i18n['交易成功'];
          case 6:
            return global.i18n['售后中'];
          case 7:
            return global.i18n['售后已完成'];
          case -1:
            return global.i18n['交易关闭'];
          default:
            return '';
        }
      },
      // 自提状态过滤器
      filterInviteStatus(val) {
        switch (val) {
          case 0:
            return '待付款';
          case 1:
            return '待取货';
          case 2:
            return '待取货';
          case 3:
            return '提货成功';
          case 4:
            return '交易成功';
          case 6:
            return '售后中';
          case 7:
            return '售后已完成';
          case -1:
            return '交易关闭';
          default:
            return '';
        }
      },
      // 售后状态过滤器
      filterRefundStatus(val,refund_type,express_no) {
        switch (val) {
          case 0:
            return global.i18n['待审核'];
          case 1:
            let tips = global.i18n['待寄回'];
            if((refund_type == 1 || refund_type == 2) && express_no) tips = global.i18n['待退款'];
            return tips;
          case 2:
            return global.i18n['待退款'];
          case 3:
            return global.i18n['售后已完成'];
          case -1:
            return global.i18n['商家驳回'];
          case -2:
            return global.i18n['售后关闭'];
          default:
            return '';
        }
      },
      // 售后类型过滤器
      filterRefundType(val) {
        console.log('val', val);
        switch (val) {
          case '1':
            return '退款';
            break;
          case '2':
            return '退货';
            break;
          case '3':
            return '换货';
            break;
        }
      },
      filterPriceInt(val){
        if(!val) return "";
        return val.toString().split('.')[0];
      },
      filterPriceFloat(val){
        if(!val) return "";
        return val.toString().split('.')[1];
      },
    }
  };
</script>

<style lang="scss" scoped>
  .page {
    min-height: calc(100vh - 88rpx);
  }

  /* 样式主题色 */
  .text-theme {
    color: $theme;
  }

  /* 订单状态Tab栏-开始 */
  .navbar {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 88rpx;
    padding: 0 24rpx;
    background: #ffffff;
    position: sticky;
    z-index: 99;
    top: 0;

    .nav-item {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100%;
      font-size: 28rpx;
      color: #666;
      position: relative;

      &.current {
        color: $theme;

        &:after {
          content: '';
          position: absolute;
          left: 50%;
          bottom: 0;
          transform: translateX(-50%);
          width: 40rpx;
          height: 8rpx;
          background: $bgtheme;
          border-radius: 4rpx;
        }
      }
    }
  }

  /* 订单状态Tab栏-结束 */

  .order-item {
    display: flex;
    flex-direction: column;
    padding: 0 24rpx;
    background: #fff;
    margin: 24rpx 24rpx 0 24rpx;
    border-radius: 24rpx;

    .i-top {
      display: flex;
      align-items: center;
      height: 102rpx;
      font-size: 28rpx;
      color: #666;
      position: relative;

      .time {
        flex: 1;
      }

      .so {
        flex-shrink: 0;
      }
    }

    /* 订单商品展示样式-开始 */
    .goods-box {
      border-bottom: 1px solid #eeeeee;

      .goods-box-single {
        display: flex;
        padding-bottom: 32rpx;

        .goods-img {
          display: block;
          width: 200rpx;
          height: 200rpx;
          background-color: #eeeeee;
          border-radius: 24rpx;
        }

        .right {
          width: 0;
          flex: 1;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          overflow: hidden;
          margin-left: 24rpx;

          .attr-box {
            font-size: 24rpx;
            color: #f8f8f8;
            padding: 10rpx 12rpx;
          }
        }
      }
    }

    /* 订单商品展示样式-结束 */

    /* 订单操作-开始 */
    .action-box {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      height: 112upx;
      position: relative;

      .action {
        display: flex;
        align-items: center;
        width: 160rpx;
        height: 56rpx;
        font-size: 24rpx;
        border-radius: 28rpx;
        padding: 0;
        color: #333;
        background-color: #f6f6f6;
        margin-left: 20rpx;
      }

      .action:last-child {
        color: #fff;
        background: $bgtheme;
      }

      .have_click {
        background-color: #bfbfbf !important;
      }

      .action+.action {
        margin-left: 20rpx;
      }
    }

    /* 订单操作-结束 */
  }

  // 取消订单弹出层-开始
  .cancel-order-pop {
    border-radius: 24rpx 24rpx 0 0;

    .pop-title {
      line-height: 114rpx;
      height: 114rpx;
      text-align: center;
      font-size: 36rpx;
      font-weight: bold;
    }

    .pop-count {
      .tips {
        line-height: 90rpx;
        background-color: #f8f8f8;
        padding: 0 24rpx;
        color: #666;
      }

      .pop-count-list {
        padding: 32rpx 24rpx;

        .item {
          padding-bottom: 32rpx;

          .item-img {
            width: 32rpx;
            height: 32rpx;
          }
        }
      }
    }

    .pop-footer {
      height: 110rpx;
      padding: 0 24rpx;
      border-top: 1px solid #eeeeee;

      .btn {
        width: 328rpx;
        height: 80rpx;
        line-height: 80rpx;
        border-radius: 80rpx;
        text-align: center;

        &.btn-type-1 {
          background-color: #f6f6f6;
        }

        &.btn-type-2 {
          color: white;
          background: $bgtheme;
        }
      }
    }
  }

  // 取消订单弹出层-结束

  .price-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 0 0 0;
    font-size: 24rpx;
    color: #333333;

    .num {
      margin: 0 8upx;
      color: #333333;
    }

    .price {
      font-size: 40rpx;
      color: #333333;

      &:before {
        content: '￥';
        font-size: 24rpx;
        margin: 0 2upx 0 8upx;
      }
    }
  }

  .refund-tag {
    font-size: 20rpx;
    padding: 0 8rpx;
    background: rgba(47, 152, 254, 0.06);
    border: 1rpx solid #2f98fe;
    border-radius: 40rpx 40rpx 0rpx 40rpx;
    color: #2f98fe;
    margin-right: 8rpx;
  }

  .block-200 {
    width: 200rpx;
    height: 200rpx;
    flex-shrink: 0;
  }

  .action-btn {
    width: 160rpx;
    height: 56rpx;
    background: #f6f6f6;
    border-radius: 28rpx;
    font-size: 24rpx;
    color: #333333;
    line-height: 56rpx;
    text-align: center;
  }
  .recom{
    color: #333333!important;
    background: #f6f6f6!important;
  }
</style>
